package cn.iocoder.yudao.module.pay.controller.app.collect;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.controller.admin.collect.vo.PayCollectOrderPageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.collect.vo.PayCollectOrderRespVO;
import cn.iocoder.yudao.module.pay.controller.app.collect.vo.AppPayCollectOrderSaveReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.paycollectorder.PayCollectOrderDO;
import cn.iocoder.yudao.module.pay.service.paycollectorder.PayCollectOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户app - 收款订单")
@RestController
@RequestMapping("/pay/collect-order")
@Validated
public class AppPayCollectOrderController {

    @Resource
    private PayCollectOrderService collectOrderService;

    @PostMapping("/create")
    @Operation(summary = "创建收款订单")
    public CommonResult<Long> createCollectOrder(@Valid @RequestBody AppPayCollectOrderSaveReqVO createReqVO) {
        return success(collectOrderService.createCollectOrder(createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得收款订单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<PayCollectOrderRespVO> getCollectOrder(@RequestParam("id") Long id) {
        PayCollectOrderDO collectOrder = collectOrderService.getCollectOrder(id);
        return success(BeanUtils.toBean(collectOrder, PayCollectOrderRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得收款订单分页")
    public CommonResult<PageResult<PayCollectOrderRespVO>> getCollectOrderPage(@Valid PayCollectOrderPageReqVO pageReqVO) {
        PageResult<PayCollectOrderDO> pageResult = collectOrderService.getCollectOrderPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PayCollectOrderRespVO.class));
    }

}